package com.sjk.flink.schema;

import cn.hutool.core.date.DateUtil;
import networknt.schema.Format;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class CustomDateTimeFormat implements Format {

    @Override
    public String getName() {
        return "date-time";
    }

    @Override
    public boolean matches(String value) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setLenient(true);
        try {
            format.parse(value);
            DateUtil.parse(value);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public String getErrorMessageDescription() {
        return "(正确案例 2023-11-09 12:00:00)";
    }

    public static void main(String[] args){
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            format.setLenient(true);
            format.parse("1960612-12-14 01:56:40");
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }

}